﻿using System.Configuration;

namespace SeleniumToolkit.Config
{
    ///<summary>
    /// Configuration element for BrowserMap
    ///</summary>
    public class BrowserMapElement : ConfigurationElement
    {
        /// <summary>
        /// Static Constructor
        /// </summary>
        static BrowserMapElement()
        {
            PropertyCollection = new ConfigurationPropertyCollection();
            KeyProperty = new ConfigurationProperty(KeyPropertyKey, typeof(string), null, ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey);
            ValueProperty = new ConfigurationProperty(ValueKey, typeof(string), null, ConfigurationPropertyOptions.IsRequired);

            PropertyCollection.Add(KeyProperty);
            PropertyCollection.Add(ValueProperty);
        }

        #region Constructors
        ///<summary>
        /// Default Constructor
        ///</summary>
        public BrowserMapElement()
        {
        }
        /// <summary>
        /// Constructor with key
        /// </summary>
        /// <param name="key">Browser Key</param>
        public BrowserMapElement(string key)
        {
            Key = key;
            Value = key;
        } 
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets the BrowserMap Key
        /// </summary>
        [ConfigurationProperty(KeyPropertyKey, IsKey = true, IsRequired = true)]
        public string Key
        {
            get { return (string)base[KeyProperty]; }
            set
            {
                base[KeyProperty] = value;
            }
        }

        /// <summary>
        /// Gets or sets the BrowserMap Value
        /// </summary>
        [ConfigurationProperty(ValueKey, IsRequired = true)]
        public string Value
        {
            get { return (string)base[ValueProperty]; }
            set
            {
                base[ValueProperty] = value;
            }
        }

        /// <summary>
        /// Overrides the default Property collection
        /// </summary>
        protected override ConfigurationPropertyCollection Properties
        {
            get
            {
                return PropertyCollection;
            }
        } 
        #endregion

        static readonly ConfigurationPropertyCollection PropertyCollection;
        static readonly ConfigurationProperty KeyProperty;
        private const string KeyPropertyKey = "key";

        static readonly ConfigurationProperty ValueProperty;
        private const string ValueKey = "value";
    }
}
